package com.atung.service.impl;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.atung.model.Content;
import com.atung.model.TemplateMessage;

import cn.hutool.http.HttpUtil;


@Service
public class TemplateTool {

	private  String departMessage="t65hycOqEZuV820WozYW1m1mp8-U6nR5jTDpFjkTDyE";
	
	//发布订阅消息模板
	public  String sendTemplateURL="https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=ACCESSTOKEN";

	/**
	 * 发车通知
	 * @param tousers
	 * @param template_id
	 * @throws Exception
	 */
	public  void sendPostTemplateDepartMessage(String accessToken) throws Exception{
		
//		List<ResponseOpenIdAndOrderId> openIdAndOrderIdList=departMessageDTO.getUserMessage();
//		if(openIdAndOrderIdList.size()<=0){
//			
//		}else{
			 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm");
	        TemplateMessage mess = new TemplateMessage();
	        mess.setTemplate_id(departMessage);
	        //模板数据封装实体
	        Map<String, Content> data = new HashMap<String,Content>();
	        //出发地目的地
//	        data.put("thing2.DATA",new Content(departMessageDTO.getLicencePlate()));
	        //出发时间
//	        data.put("time3.DATA", new Content(sdf.format(new Date(DateTimeTool.localDateTimeToMillis(departMessageDTO.getStartData())))));

	        mess.setTouser("");
	        mess.setData(data);
	        String json = JSONObject.toJSONString(mess);
	   		String a=HttpUtil.post(sendTemplateURL.replace("ACCESSTOKEN", accessToken), json);
	   		System.err.println(a);
		}
//	}
}
